<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
﻿<!DOCTYPE HTML>
<html>
<head>
<jsp:include page="common_header.jsp" flush="true"></jsp:include>
<title>角色管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 用户管理 <span class="c-gray en">&gt;</span> 角色管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="cl pd-5 bg-1 bk-gray"> 
		<span class="l">
			<a href="javascript:;" onclick="batchDel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> 
			<a class="btn btn-primary radius" href="javascript:;" onclick="admin_role_add('添加角色','${path}/user/toPage.do?page=admin-role-add','800')"><i class="Hui-iconfont">&#xe600;</i> 添加角色</a> 
		</span> 
		<span class="r">共有数据：<strong id="totalRow">-</strong> 条</span> 
	</div>
	<table id="roleTbl" class="table table-border table-bordered table-hover table-bg">
		<thead>
			<tr>
				<th scope="col" colspan="6">角色管理</th>
			</tr>
			<tr class="text-c">
				<th width="25"><input type="checkbox" value="" name="" onclick="checkAll(this)"/></th>
				<th width="40">序号</th>
				<th width="200">角色名</th>
				<th>角色描述</th>
				<th width="300">创建时间</th>
				<th width="70">操作</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
</div>
<jsp:include page="_footer.jsp" flush="true"></jsp:include>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">

$(function(){
	
	initDg('roleTbl', {
		queryUrl : '${path}/sysRole/query.do',
		beforeAjax : function(data){
		},
		sucessAjax : function(result){
			$('#totalRow').html(result.data.recordsTotal);
		},
		columns: [
            { "data": null },
            { "data": null },
            { "data": "name" },
            { "data": "desp" },
            { "data": "createTime" },
            { "data": null }
        ],
        rowCallback : function(row, data, index){
        	$('td:eq(4)', row).html( fmtMillsec(data.createTime, true) );
    		$('td:eq(5)', row).html( ' <a title="编辑" href="javascript:;" onclick="admin_role_edit(\'角色编辑\',\'${path}/user/toPage.do?page=admin-role-add\',\''+data.id+'\')" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> <a title="删除" href="javascript:;" onclick="admin_role_del(this,\''+data.id+'\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>' );
        }
	});
	
});

/**
 * 子页面调用父页面该方法
 */
function refresh(index){
	queryUser();
	layer.close(index);
}

/**
 * 触发dataTable的查询
 */
function queryUser(){
	$("#roleTbl").dataTable().fnDraw(false);
}


/*管理员-角色-添加*/
function admin_role_add(title,url,w,h){
	h = $(window).height() - 50;
	layer.open({
		type: 2,
		area: [w+'px', h +'px'],
		fix: false, //不固定
		maxmin: true,
		shade:0.4,
		title: title,
		content: url,
		success: function(layero, index){
		    var body = layer.getChildFrame('body', index);
		    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
		    iframeWin.initPermsData();
	    }
	});
}
/*管理员-角色-编辑*/
function admin_role_edit(title,url,id,w,h){
	w= 800;
	h= 470;
	layer.open({
		type: 2,
		area: [w+'px', h +'px'],
		fix: false, //不固定
		maxmin: true,
		shade:0.4,
		title: title,
		content: url,
		success: function(layero, index){
		    var body = layer.getChildFrame('body', index);
		    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
		    iframeWin.fillData(id);
	    }
	});
}
/*管理员-角色-删除*/
function admin_role_del(obj,id){
	layer.confirm('角色删除须谨慎，确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '${path}/sysRole/delete.do',
			data: 'ids='+id,
			dataType: 'json',
			success: function(data){
				if (data.code == 0) {
					layer.msg('已删除!',{icon:1,time:1000});
					queryUser();
				}else{
					layer.msg('删除失败!',{icon:1,time:1000});
				}
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}

function batchDel(){
	var idArr = [];
	$('#roleTbl tbody :checked').each(function(){
		idArr.push($(this).next().val());
	});
	if (idArr.length > 0) {
		layer.confirm('确认要删除这'+idArr.length+'条记录吗？',function(index){
			$.ajax({
				url: '${path}/sysRole/delete.do',
				data: 'ids='+idArr.join(','), 
				type: "POST",
				success: function(data, textStatus){
					if (data.code == 0) {
						layer.msg('已删除!',{icon:1,time:1000});
						queryUser();
					}else{
						layer.msg('删除失败!',{icon:1,time:1000});
					}
				},
				error: function (data, textStatus, errorThrown) {
					var s=JSON.stringify(data);
				}
			});			
		});
	}else{
		layer.alert('请选择记录!',{icon:1,time:2000});
	}
}
</script>
</body>
</html>
